cmake_minimum_required(VERSION 2.8.3)
project(lidar_apollo_cnn_seg_detect)

find_package(autoware_build_flags REQUIRED)
find_package(catkin REQUIRED COMPONENTS
  autoware_msgs
  geometry_msgs
  pcl_ros
  roscpp
  sensor_msgs
  tf
  tf_conversions
)

find_package(CUDA)
find_package(OpenCV REQUIRED)

catkin_package(
  INCLUDE_DIRS include
)

###CAFFE
set(CAFFE_PATH "$ENV{HOME}/caffe/distribute")

AW_CHECK_CUDA()

if(USE_CUDA AND EXISTS "${CAFFE_PATH}")
  include_directories(${CUDA_INCLUDE_DIRS})

  IF ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^arm")
    link_directories(/usr/lib/arm-linux-gnueabihf/tegra)
  endif ()

  include_directories(
    include
    ${catkin_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
    ${CAFFE_PATH}/include
  )

  add_executable(lidar_apollo_cnn_seg_detect
    nodes/lidar_apollo_cnn_seg_detect_node.cpp
    nodes/cnn_segmentation.cpp
    nodes/cluster2d.cpp
    nodes/feature_generator.cpp
  )
  target_link_libraries(lidar_apollo_cnn_seg_detect
    ${catkin_LIBRARIES}
    ${OpenCV_LIBRARIES}
    ${CUDA_LIBRARIES}
    ${CUDA_CUBLAS_LIBRARIES}
    ${CUDA_curand_LIBRARY}
    ${CAFFE_PATH}/lib/libcaffe.so
    glog
  )
  add_dependencies(lidar_apollo_cnn_seg_detect
    ${catkin_EXPORTED_TARGETS}
  )

  install(TARGETS
    lidar_apollo_cnn_seg_detect
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  )
  install(DIRECTORY launch/
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
    PATTERN ".svn" EXCLUDE
  )
else()
  message("'Caffe' is not installed. 'lidar_apollo_cnn_seg_detect' will not be built.")
endif()
